import * as https from 'node:https';

export default (appId: string, appSecret: string) =>
  new Promise<{ access_token: string; expires_in: number }>(
    (resove, reject) => {
      https
        .get(
          `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${appId}&secret=${appSecret}`,
          (res) => {
            res.on('data', (d) => {
              resove(JSON.parse(d.toString()));
            });
          },
        )
        .on('error', (e) => {
          reject(e);
        });
    },
  );
